package hlhj.fhp.supreme.activitys

import android.os.Build
import android.webkit.WebChromeClient
import android.webkit.WebSettings
import android.webkit.WebViewClient
import com.lzy.okgo.OkGo
import com.lzy.okgo.callback.StringCallback
import com.lzy.okgo.model.Response
import hlhj.fhp.supreme.BaseAty
import hlhj.fhp.supreme.R
import hlhj.fhp.supreme.js.JsHelper
import hlhj.fhp.supreme.network.Urls
import hlhj.fhp.supreme.utils.MyUtils
import hlhj.fhp.supreme.utils.SPHelper
import kotlinx.android.synthetic.main.activity_html_aty.*
import java.util.*

class HtmlAty : BaseAty() {
    private var first=true
    override fun getContentId(): Int {
        return R.layout.activity_html_aty
    }

    override fun onResume() {
        super.onResume()
        webView.resumeTimers()
    }

    override fun onPause() {
        super.onPause()
        webView.pauseTimers()
    }
    override fun initView() {

        val webSettings = webView.settings
        webSettings.javaScriptEnabled=true
        webSettings.domStorageEnabled = true
        webSettings.javaScriptCanOpenWindowsAutomatically = true
        if (Build.VERSION.SDK_INT >= 19) {
            webView.settings.cacheMode = WebSettings.LOAD_CACHE_ELSE_NETWORK;
        }
        val appCachePath = applicationContext.cacheDir.absolutePath
        webSettings.setAppCachePath(appCachePath)
        webSettings.setAllowFileAccess(true)
        webSettings.setAppCacheEnabled(true)
        webView.addJavascriptInterface(JsHelper(this, intent.getIntExtra("id", 0).toString(), webView,SPHelper.getToken(this)),"goodContact")
        webView.webViewClient=object : WebViewClient(){
        }
        webView.webChromeClient=object :WebChromeClient(){
        }
        /*Thread(Runnable {
            Thread.sleep(10)
            webView.post {
                MyUtils.toast("加载页面")
                webView.loadUrl("file:///android_asset/home/details.html")
            }
        }).start()*/
        val timer = Timer()
        val task=object :TimerTask(){
            override fun run() {
                runOnUiThread {
                    webView.loadUrl("file:///android_asset/home/details.html")
                }
            }
        }
        timer.schedule(task,20)
    }

}
